package com.ce.pms.customer.web;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import com.ce.pms.charge.vo.BankVO;
import com.ce.pms.common.model.SysrefcodeDO;
import com.ce.pms.common.web.ICacheManage;
import com.ce.pms.customer.model.ProRightDO;
import com.ce.pms.customer.service.IOwnerService;
import com.ce.pms.customer.vo.CustomerHouseVO;
import com.ce.pms.customer.vo.CustomerVO;
import com.ce.pms.customer.vo.IndividualVO;
import com.ce.pms.customer.vo.InterestVO;
import com.ce.pms.customer.vo.OrganizationVO;
import com.ce.pms.exception.BusinessException;
import com.ce.pms.house.vo.HouseVO;
import com.ce.util.BlankUtil;
import com.ce.util.DateUtil;
import com.sitechasia.webx.core.annotation.Out;
import com.sitechasia.webx.core.annotation.Read;
/**
 * 功能描述: 业主ACTION
 * <p>
 * 版权所有：中企动力
 * <p>
 * 未经本公司许可，不得以任何方式复制或使用本程序任何部分
 *
 * @author 付湘辉
 * @Created on 2008-05-22
 */
public class OwnerAction extends CustomerAction {

	/**
	 * 房屋信息集合key
	 */
	public static final String WEBCACHE_KEY_OWNER_HOUSE = "ownerHouseColletion";


	/**
	 * 基本资料缓存列表为空
	 */
	private static final String BASE_CACHE_LIST_ISNULL = "customerIsNumm";

	/**
	 * 房屋缓存列表为空
	 */
	private static final String HOUSE_CACHE_LIST_ISNULL = "houseListIsNumm";
	/**
	 * 房屋缓存列表为空
	 */
	private static final String HOUSE_CACHE_LIST_ISNULL2 = "houseListIsNull";

	/**
	 * 业主服务类接口
	 */
	private IOwnerService ownerService;

	/**
	 * 产权和合同号都为空
	 */
	private static final String PRORIGHT_AND_CONTRACT_ISNULL = "proORconIsNull";

	/**
	 * @roseuid 4834E92E0000
	 */
	public OwnerAction() {

	}

	/**
	 *
	 * 功能描述: 在页面点击保存按钮，添加业主信息，这些信息将从缓存中取得
	 *
	 * @author 付湘辉
	 * Created on:2008-6-3
	 *
	 * 修改原因：
	 * @return String 返回结果
	 */
	@Override
	public String addCustomer() {

		List<CustomerHouseVO> houseList= this.getOwnerHouseListCacheHerebyFlag(true);//得到住房信息列表
		if (BlankUtil.isBlank(houseList)) {
			//不能为空
			this.renderText(OwnerAction.HOUSE_CACHE_LIST_ISNULL);
			return null;
		}
        houseList= this.getOwnerHouseListCacheHerebyFlag(false);//得到住房信息列表
		List<CustomerVO> customerList = super.getCustomerBaseListCacheHerebyFlag(true);//得到住户信息列表
		if (BlankUtil.isBlank(customerList)) {
			//不能为空
			this.renderText(OwnerAction.BASE_CACHE_LIST_ISNULL);
			return null;
		}
        customerList = super.getCustomerBaseListCacheHerebyFlag(false);//得到住户信息列表

        try {
	        String result = this.ownerService.addCustomer(houseList, customerList);

			if ("true".equals(result)) {
				super.setAllStatusToDone(CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL);
				super.setAllStatusToDone(OwnerAction.WEBCACHE_KEY_OWNER_HOUSE);
				this.renderText("true");
			}else{
				this.renderText("false");
			}

        } catch(BusinessException be){
//        	super.setAllStatusToDone(CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL);
//			super.setAllStatusToDone(OwnerAction.WEBCACHE_KEY_OWNER_HOUSE);
        	throw be;
        } catch (Exception e) {
//        	super.setAllStatusToDone(CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL);
//			super.setAllStatusToDone(OwnerAction.WEBCACHE_KEY_OWNER_HOUSE);
            super.logger.fatal(e.getMessage(), e);
            throw new BusinessException("customer:owner_addowner_fail_exception",
            							BusinessException.FAILURE);
        }

        return null;
	}

	/**
	 * 功能描述：向缓存中添加住房信息，根据参数customerHouseVO查询与之相关的产权房信息
	 *
	 * @author 付湘辉
	 * Created on 2008-05-23
	 *
	 * @param currentPage
	 *            当前页
	 * @param pageSize
	 *            页大小
	 * @param customerHouseVO
	 *            住房信息VO对象
	 * @return boolean
	 */
	@Override
	public String addCustomerHouseCache(@Read(key = "ec_p")Integer currentPage,
			                            @Read(key = "ec_crd") Integer pageSize,
			                            @Read CustomerHouseVO customerHouseVO) {

		if (BlankUtil.isBlank(customerHouseVO)) {
			this.renderText(super.getLocaleMessage("customer:owner_must_choose_house_exception"));
			return null;
		}

		//此处添加查询房屋是否正处于退伙中，以判断该房间能否新增业主
		if (this.isTuihuoing(customerHouseVO)) {
//			this.renderText(super.getLocaleMessage("customer:owner_house_is_tuihuoing_exception"));
			throw new BusinessException("customer:owner_house_is_tuihuoing_exception",BusinessException.WARNING);
//			return null;
		}

		super.validationHouseOnSave(customerHouseVO.getHouseNumber(),OwnerAction.WEBCACHE_KEY_OWNER_HOUSE);

		CustomerHouseVO userSelectchvo = null;

		List<CustomerHouseVO> list
			= this.ownerService.getCustomerHouseList(customerHouseVO.getHouseNumber());

		if (!BlankUtil.isBlank(list)) {
			List<CustomerHouseVO> tempList = new ArrayList<CustomerHouseVO>();
			for (int i = 0; i < list.size(); i++) {
				CustomerHouseVO chvo = list.get(i);
				chvo.setCreator(super.getUserId());

				//处理划款银行帐号，此处业务处理规则有待与需求人员沟通
				//１１１１１１１1：页面传来划款银行帐号数据是否用到所选房屋及带过来的房屋
				//2３：如果所选房屋已有帐号，是覆盖还是不加
				if (canAddBankAccount(customerHouseVO)
						&& ProRightDO.CHARGE_SELECT_MERGER.equals(chvo.getChargeSelect())) {
					updateCustomerHouseBankAccValues(customerHouseVO, chvo);
				}

				if (chvo.getHouseNumber().equalsIgnoreCase(customerHouseVO.getHouseNumber())) {

					// 修改合同号，房产证号
					// 只有在用户输入了合同号和产权证号时才修改
					chvo.setHouseContractNumber(BlankUtil.isBlank(customerHouseVO.getHouseContractNumber())
                                                                     ? chvo.getHouseContractNumber()
                                                                     : customerHouseVO.getHouseContractNumber());
					chvo.setHousePropertyNo(BlankUtil.isBlank(customerHouseVO.getHousePropertyNo())
                                                             ? chvo.getHousePropertyNo()
                                                             : customerHouseVO.getHousePropertyNo());
					userSelectchvo = chvo;
					if (canAddBankAccount(customerHouseVO)) {
						updateCustomerHouseBankAccValues(customerHouseVO, userSelectchvo);
					}
				}else{
					tempList.add(chvo);
//					this.addOneCustomerHouseToCache(OwnerAction.WEBCACHE_KEY_OWNER_HOUSE, chvo, false);
				}
			}

			for (CustomerHouseVO houseVO : tempList) {
				this.addOneCustomerHouseToCache(OwnerAction.WEBCACHE_KEY_OWNER_HOUSE, houseVO, false);
			}
			//最后添加用户选择（或输入）的房间
			this.addOneCustomerHouseToCache(OwnerAction.WEBCACHE_KEY_OWNER_HOUSE, userSelectchvo, false);

		}

		this.setAttribute("ownerHouseFlag", "true");

		return null;
	}

	/**
	 * 功能描述：添加一个个人业主到缓存中
	 *
	 * @author 付湘辉
	 * Created on 2008-05-29
	 *
	 * @param individualVO 个人业主VO对象
	 * @return String
	 */
	public String addIndividualOwnerCache(@Read IndividualVO individualVO){
		individualVO.setParticipantTypeCode(CustomerVO.INDIVIDUAL_CODE);

		this.validateOwnerOnSave(individualVO,OwnerAction.WEBCACHE_KEY_OWNER_HOUSE);

//		CustomerVO customervo = super.getOneCustomerBaseBycertificateTypeAndNoFromCache(CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL, individualVO.getCertificateType(), individualVO.getCertificateNo());
//		if (!BlankUtil.isBlank(customervo)) {
//			super.checkIsException("customer:owner_exist_same_type_no_exception",BusinessException.WARNING);
//		}
		String sexName = super.getSexDisplayValueById(individualVO.getSex());
		individualVO.setSexDisplayValue(sexName);
		individualVO.setCertificateTypeName(super.getCertifiCateTypeName(individualVO.getCertificateType()));
		individualVO.setBirthDateDisplayValue(DateUtil.convertDateToStr(individualVO.getBirthDate(), DateUtil.DEFAULT_SHORT_DATE_FORMAT));
		individualVO.setCustomerTypeCode(CustomerVO.OWNER_CODE);//001业主
		individualVO.setParticipantTypeCode(CustomerVO.INDIVIDUAL_CODE);//001个人
		individualVO.setCustomerType(CustomerVO.OWNER_INDIVIDUAL);
		individualVO.setCreator(super.getUserId());
		//兴趣爱好
		individualVO.setInterestNameStr(this.customerService.assemblyInterestNameString(individualVO.getInterest()));
		super.addOneCustomerBaseToCache(CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL, individualVO, false);
		this.setAttribute("sucessed",Boolean.valueOf(true));
		return "ownerBaseAdd";
	}

	/**
	 * 功能描述：在指定key的缓存集合中添加一个住房信息VO对象
	 * 		   由标志isFirst决定是添加到缓存头还是尾部
	 *
	 * @author 付湘辉
	 * Created on 2008-05-28
	 *
	 * @param key
	 *            在缓存中的key
	 * @param customerHouseVO
	 *            待添加的住房信息VO对象
	 * @param isFirst
	 *            添加到头尾标志
	 * @return boolean
	 */
	@Override
	@SuppressWarnings("unchecked")
	public boolean addOneCustomerHouseToCache(String key, CustomerHouseVO customerHouseVO, boolean isFirst) {
		boolean flag = false;

		if (BlankUtil.isBlank(key)) {
			key = OwnerAction.WEBCACHE_KEY_OWNER_HOUSE;
		}

		flag = super.addOneCustomerHouseToCache(key, customerHouseVO, isFirst);

		return flag;
	}

	/**
	 * 功能描述：添加一个组织业主到缓存中
	 *
	 * @author 付湘辉
	 * Created on 2008-05-29
	 *
	 * @param organizationVO 组织业主VO对象
	 * @return String
	 */
	public String addOrganizationOwnerCache(@Read OrganizationVO organizationVO){

		if (BlankUtil.isBlank(organizationVO)) {
			return "";
		}

		organizationVO.setParticipantTypeCode(CustomerVO.ORGNIZATION_CODE);

		this.validateOwnerOnSave(organizationVO,OwnerAction.WEBCACHE_KEY_OWNER_HOUSE);

		//法人性别显示值
		String sexDisplayValue = super.getSexDisplayValueById(organizationVO.getSex());
		organizationVO.setSexDisplayValue(sexDisplayValue);
		//代理人性别显示值
		String consignerSexDisplayValue = super.getSexDisplayValueById(organizationVO.getConsignerSex());
		organizationVO.setConsignerSexDisplayValue(consignerSexDisplayValue);
		//法人证件类型名称
		organizationVO.setCertificateTypeName(super.getCertifiCateTypeName(organizationVO.getCertificateType()));
		//代理人证件类型名称
		organizationVO.setConsignerCertificateTypeName(super.getCertifiCateTypeName(organizationVO.getConsignerCertificateType()));
		//法人出生日期显示值
		organizationVO.setCorporationBirthDateDisplayValue(DateUtil.convertDateToStr(organizationVO.getCorporationBirthDate(), DateUtil.DEFAULT_SHORT_DATE_FORMAT));

		organizationVO.setCustomerTypeCode(CustomerVO.OWNER_CODE);//业主
		organizationVO.setParticipantTypeCode(CustomerVO.ORGNIZATION_CODE);//企业
		organizationVO.setCustomerType(CustomerVO.OWNER_ORGNIZATION);

		organizationVO.setCreator(super.getUserId());
		this.addOneCustomerBaseToCache(CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL, organizationVO, false);
		this.setAttribute("sucessed",Boolean.valueOf(true));
		return "ownerBaseAdd";
	}

	/**
	 * 功能描述：清空缓存数据
	 *
	 * @author 付湘辉
	 *
	 * Created on  2008-05-22
	 * @return String
	 * @roseuid 4827E0DC00BB
	 */
	@Override
	public String clearCache() {
		super.clearCache();
		this.getRequest().getSession().removeAttribute(OwnerAction.WEBCACHE_KEY_OWNER_HOUSE);
		return "ok";
	}

	/**
	 * 功能描述：删除已存到缓存中的业主住房信息，
	 * 如果住房已有合并的产权共有房间，则会一同删除
	 *
	 * @author 付湘辉
	 *
	 * Created on  2008-05-23
	 * @param customerHouseVO 住房信息
	 * @return String
	 */
	public void deleteCustomerHouseCache(@Read CustomerHouseVO customerHouseVO) {
		super.deleteCustomerHouseCache(customerHouseVO,OwnerAction.WEBCACHE_KEY_OWNER_HOUSE);
	}
	/**
	 * 功能描述：删除一个在缓存中的个人业主基本资料信息
	 *
	 * @author 付湘辉
	 * Created on 2008-05-23
	 *
	 * @param customerVO 个人业主基本资料信息VO对象
	 * @return String
	 * @roseuid 482AA4C200DA
	 */
	public String deleteOwnerBaseCache(@Read CustomerVO customerVO) {
		if (super.deleteOneCustomerBaseFromCache(CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL, customerVO)) {
			return "true";
		}else{
			return "false";
		}

	}

	/**
	 * 功能描述：新增时修改一个在缓存中的个人业主基本资料信息
	 *
	 * @author 付湘辉
	 * Created on 2008-05-23
	 *
	 * @param individualVO 个人VO对象
	 * @return String
	 * @roseuid 482AA49C036B
	 */
	public String editIndividualOwnerCache(@Read IndividualVO individualVO) {
		individualVO.setParticipantTypeCode(CustomerVO.INDIVIDUAL_CODE);
		individualVO.setCertificateTypeName(super.getCertifiCateTypeName(individualVO.getCertificateType()));
		this.validateOwnerOnEditSave(individualVO, WEBCACHE_KEY_OWNER_HOUSE, CustomerAction.AT_ADD_EDIT);
		if (this.editOneCustomerBaseAsCache(CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL, individualVO)) {
			return "true";
		} else{
			return "false";
		}

	}

	/**
	 * 功能描述：在指定key的缓存集合中删除一个住房信息VO对象，
	 * 如果该对象并没有持久化过，则直接从缓存中删除，否则
	 * 是将其操作状态改为删除状态<br>
	 * 此方法要求参数CustomerHouseVO对象覆写<b>Object.equals()<b>方法
	 * @author 付湘辉
	 * Created on 2008-05-28
	 *
	 * @param key
	 *            在缓存中的key
	 * @param customerHouseVO
	 *            待删除的住房信息VO对象
	 * @return boolean
	 */
//	@Override
//	@SuppressWarnings("unchecked")
//	public boolean deleteOneCustomerHouseFromCache(String key, CustomerHouseVO customerHouseVO) {
//		if (BlankUtil.isBlank(key)) {
//			key = OwnerAction.WEBCACHE_KEY_OWNER_HOUSE;
//		}
//		boolean flag =  false;
//
//		flag = super.deleteOneCustomerHouseFromCache(key, customerHouseVO);
//
//		return flag;
//
//	}


	/**
	 * 功能描述：在指定key的缓存集合中修改一个住房信息VO对象
	 *
	 * @author 付湘辉
	 * Created on 2008-05-28
	 *
	 * @param key
	 *            在缓存中的key
	 * @param customerHouseVO
	 *            待修改的住房信息VO对象
	 * @return boolean
	 */
	@Override
	@SuppressWarnings("unchecked")
	public boolean editOneCustomerHouseAsCache(String key, CustomerHouseVO customerHouseVO) {

		boolean flag =  false;

		if (BlankUtil.isBlank(key)) {
			key = OwnerAction.WEBCACHE_KEY_OWNER_HOUSE;
		}

		flag = super.editOneCustomerHouseAsCache(key, customerHouseVO);

		return flag;

	}

	/**
	 * 功能描述：新增时修改一个在缓存中的企业业主基本资料信息
	 *
	 * @author 付湘辉
	 * Created on 2008-05-23
	 *
	 * @param organizationVO 组织VO对象
	 * @return String
	 * @roseuid 482BD65001D4
	 */
	public String editOrganizationBaseCache(@Read OrganizationVO organizationVO) {
		organizationVO.setParticipantTypeCode(CustomerVO.ORGNIZATION_CODE);
		// 法人证件类型名称
		organizationVO.setCertificateTypeName(super.getCertifiCateTypeName(organizationVO.getCertificateType()));
		// 代理人证件类型名称
		organizationVO.setConsignerCertificateTypeName(super.getCertifiCateTypeName(organizationVO.getConsignerCertificateType()));
		validateOwnerOnEditSave(organizationVO,OwnerAction.WEBCACHE_KEY_OWNER_HOUSE, CustomerAction.AT_ADD_EDIT);
		if (this.editOneCustomerBaseAsCache(CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL, organizationVO)) {
			return "true";
		} else{
			return "false";
		}
	}

	/**
	 * 功能描述：修改一个已存到缓存中的住房信息
	 *
	 * @author 付湘辉
	 *
	 * Created on  2008-05-22
	 * @param customerHouseVO 住房信息
	 * @return String
	 * @roseuid 482A86AA003E
	 */
	public String editOwnerHouseCache(@Read CustomerHouseVO customerHouseVO) {
		this.editOneCustomerHouseAsCache(OwnerAction.WEBCACHE_KEY_OWNER_HOUSE, customerHouseVO);
		return null;
	}

	/**
	 * 功能描述： 修改个人业主信息
	 * @param individualVO
	 * @return
	 * Create author:付湘辉
	 * Create on:2008-5-30
	 * Edit author:
	 * Edit on:
	 * Why:
	 */
	public String editOwnerIndividual(@Read IndividualVO individualVO) {
		super.checkIsException("common:parameters_null_exception, ", individualVO);
		individualVO.setParticipantTypeCode(CustomerVO.INDIVIDUAL_CODE);
		String certificateTypeName = super.getCertifiCateTypeName(individualVO.getCertificateType());
		individualVO.setCertificateTypeName(certificateTypeName);
		Boolean res = validateOwnerOnEditSave(individualVO,OwnerAction.WEBCACHE_KEY_OWNER_HOUSE, CustomerAction.AT_EDIT);
		if (!res) {
//			this.renderText(super.getLocaleMessage("customer:customer_add_eidt_save_fail_exception"));
			this.renderText("false");
			return null;
		}
		try {
	        String message = "";
	        boolean successFlat = false;
	        //先拿过滤了删除状态的缓存记录
	        List<CustomerHouseVO> houseList
	                    = super.getCustomerHouseListCacheHerebyFlag(OwnerAction.WEBCACHE_KEY_OWNER_HOUSE, true);// 得到住房信息列表
	        if (SysrefcodeDO.CONSTANTS_ONE > houseList.size()) {
	            this.renderText("houseIsNull");
	            return null;
	        }
	        //再拿所有缓存记录
	        houseList = this.getCustomerHouseListCacheHerebyFlag(OwnerAction.WEBCACHE_KEY_OWNER_HOUSE, false);// 得到住房信息列表

	        individualVO.setCreator(this.getUserId());

	        // 如果修改的是同一个人
	        if (BlankUtil.isBlank(individualVO.getParticipantId())
	                || individualVO.getParticipantId().equals(individualVO.getOldParticipantId())) {
	            successFlat
	                = this.editOneCustomerBaseAsCache(CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL, individualVO);
	        } else { // 如果修改了另一个人

	            IndividualVO individualVOTemp
	                = (IndividualVO) super.getOneCustomerBaseByIndexFromCache(
	                                                                CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL,
	                                                                individualVO.getIndex());

	            String isSave = individualVOTemp == null ? "" : individualVOTemp.getHasSave();

	            // 如果还没有保存过的，直接修改就行
	            if (ICacheManage.UNSAVE.equals(isSave)) {
	                individualVO.setOldParticipantId(null);
	                successFlat = super.editOneCustomerBaseAsCache(
	                                                    CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL, individualVO);
	            } else {// 如果是保存过的，要解除原来的关系，建立新的关系

	                // 删除原来的
	                CustomerVO customerVO = new CustomerVO();
	                customerVO.setIndex(individualVO.getIndex());
	                boolean deleteFlat = super.deleteOneCustomerBaseFromCache(
	                                                                CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL, customerVO);

	                // 增加新的一个个人资料
	                if (deleteFlat) {
	                    individualVO.setCustomerType(CustomerVO.OWNER_INDIVIDUAL);
	                    individualVO.setCustomerTypeCode(CustomerVO.OWNER_CODE);
	                    individualVO.setParticipantTypeCode(CustomerVO.INDIVIDUAL_CODE);
	                    individualVO.setIndex(null);
	                    individualVO.setOldParticipantId(null);
	                    successFlat = super.addOneCustomerBaseToCache(
	                                                        CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL,
	                                                        individualVO, true);
	                }//end if (deleteFlat) {
	            }//end else {// 如果是保存过的，要解除原来的关系，建立新的关系
	        }//end else { // 如果修改了另一个人

	        List<CustomerVO> customerList = super
	                .getCustomerBaseListCacheHerebyFlag(false);// 得到住户信息列表

	        if (successFlat) {
	        		message = this.ownerService.editCustomer(houseList, customerList);
	                if ("true".equalsIgnoreCase(message)) {
	                    this.setAllStatusToDone(OwnerAction.WEBCACHE_KEY_OWNER_HOUSE);
	                    this.setAllStatusToDone(CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL);
	                }
	                message = "true";
	        } else {
	            message = "false";
	        }

	        this.renderText(message);
		} catch (BusinessException be) {
//			this.renderText("false");
//			super.setAllStatusToDone(CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL);
//			super.setAllStatusToDone(OwnerAction.WEBCACHE_KEY_OWNER_HOUSE);
			throw be;
		} catch (Exception e) {
//			this.renderText("false");
//			super.setAllStatusToDone(CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL);
//			super.setAllStatusToDone(OwnerAction.WEBCACHE_KEY_OWNER_HOUSE);
			throw new BusinessException("customer:owner_edit_fail_exception",
					BusinessException.WARNING);
		}
        return null;
    }

	/**
	 * Function: 修改业主企业信息
	 * @param organizationVO
	 * @return
	 * Create author:付湘辉
	 * Create on:2008-5-30
	 * Edit author:
	 * Edit on:
	 * Why:
	 */
	public String editOwnerOrganization(@Read OrganizationVO organizationVO) {
		super.checkIsException("common:parameters_null_exception, ", organizationVO);
		organizationVO.setParticipantTypeCode(CustomerVO.ORGNIZATION_CODE);
    	Boolean res = validateOwnerOnEditSave(organizationVO,OwnerAction.WEBCACHE_KEY_OWNER_HOUSE, CustomerAction.AT_EDIT);
		if (!res) {
//			this.renderText(super.getLocaleMessage("customer:customer_add_eidt_save_fail_exception"));
			this.renderText("false");
			return null;
		}
        String message = "";
        boolean successFlat = false;
        List<CustomerHouseVO> houseList = super.getCustomerHouseListCacheHerebyFlag(
                                                   OwnerAction.WEBCACHE_KEY_OWNER_HOUSE, true);// 得到住房信息列表
        if (SysrefcodeDO.CONSTANTS_ONE > houseList.size()) {
            this.renderText("houseIsNull");
            return null;
        }

        houseList = this.getCustomerHouseListCacheHerebyFlag(
                                        OwnerAction.WEBCACHE_KEY_OWNER_HOUSE, false);// 得到住房信息列表

        organizationVO.setCreator(this.getUserId());

        // 如果修改的是同一企业
        if (BlankUtil.isBlank(organizationVO.getParticipantId())
                || organizationVO.getParticipantId().equals(organizationVO.getOldParticipantId())) {
                successFlat = super.editOneCustomerBaseAsCache(
                                                    CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL, organizationVO);
        } else { // 如果修改了另一个企业

            OrganizationVO organizationVOTemp
                                            = (OrganizationVO) super.getOneCustomerBaseByIndexFromCache(
                                                                                            CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL,
                                                                                            organizationVO.getIndex());
            String isSave = organizationVOTemp == null ? "" : organizationVOTemp.getHasSave();

            // 如果还没有保存过的，直接修改就行
            if (ICacheManage.UNSAVE.equals(isSave)) {
                organizationVO.setOldConsignerId(null);
                organizationVO.setOldCorporationId(null);
                organizationVO.setOldParticipantId(null);
                successFlat = this.editOneCustomerBaseAsCache(
                                                CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL,organizationVO);
            } else {// 如果是保存过的，要解除原来的关系，建立新的关系

                // 删除原来的
                CustomerVO customerVO = new CustomerVO();
                customerVO.setIndex(organizationVO.getIndex());
                boolean deleteFlat = this.deleteOneCustomerBaseFromCache(
                                    CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL, customerVO);

                if (deleteFlat) {
                    organizationVO.setCustomerType(CustomerVO.OWNER_ORGNIZATION);
                    organizationVO.setCustomerTypeCode(CustomerVO.OWNER_CODE);
                    organizationVO.setParticipantTypeCode(CustomerVO.ORGNIZATION_CODE);
                    organizationVO.setIndex(null);
                    organizationVO.setOldParticipantId(null);
                    successFlat = this.addOneCustomerBaseToCache(
                                                        CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL,
                                                        organizationVO, true);
                }
            }
        }

        List<CustomerVO> customerList = super.getCustomerBaseListCacheHerebyFlag(false);//得到住户信息列表

        if (successFlat) {
        	try {
        		message = this.ownerService.editCustomer(houseList, customerList);
                if (message.equalsIgnoreCase("true")) {
                    super.setAllStatusToDone(OwnerAction.WEBCACHE_KEY_OWNER_HOUSE);
                    super.setAllStatusToDone(CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL);
                }
                message = "true";
			} catch (BusinessException be) {
//				super.setAllStatusToDone(CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL);
//				super.setAllStatusToDone(OwnerAction.WEBCACHE_KEY_OWNER_HOUSE);
				throw be;
			} catch (Exception e) {
//				super.setAllStatusToDone(CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL);
//				super.setAllStatusToDone(OwnerAction.WEBCACHE_KEY_OWNER_HOUSE);
    			throw new BusinessException("customer:owner_edit_fail_exception",
						BusinessException.WARNING);
			}

        } else {
            message = "false";
        }
        this.renderText(message);
        return null;
    }

	/**
	 * 功能描述：从住户基本资料缓存中取得分页列表
	 *
	 * @author 付湘辉
	 * Created on 2008-05-23
	 *
	 * @param currentPage 当前页码
	 * @param pageSize 页大小
	 * @return String
	 * @roseuid 482AA41F0109
	 */
	public String findOwnerBaseListCachePage(@Read(key = "ec_p") Integer currentPage,
			  @Read(key = "ec_crd",defaultValue="3")Integer pageSize ) {
		List<CustomerVO> resultList = super.findCustomerBaseListCachePage(currentPage, pageSize);

		this.setAttribute("ownerBaseList", resultList);
		this.setAttribute("totalRows", this.getTotalRowsFromCache(CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL));
		return "ownerBaseList";
	}

	/**
	 * 功能描述：从房屋信息缓存中查询业主住房信息列表
	 *
	 * @author 付湘辉
	 * Created on 2008-05-28
	 *
	 * @param currentPage 当前页码
	 * @param pageSize 页大小
	 * @return String
	 * @roseuid 48311405032C
	 */
	@SuppressWarnings("unchecked")
	public String findOwnerHouseCachePage(@Read(key = "ec_p") Integer currentPage,
										  @Read(key = "ec_crd")Integer pageSize,
										  @Read (key="contextMenuFlag") String flag) {

		List<CustomerHouseVO> resultList = this.findOwnerHouseListCacheInner(currentPage,pageSize);

		//标志flag用于在返回页面是否弹出右键菜单
		if (!BlankUtil.isBlank(flag)) {
			this.setAttribute("contextMenuFlag", flag);
		}
		this.setAttribute("ownerHouseList", resultList);
		this.setAttribute("totalRows", this.getTotalRowsFromCache(OwnerAction.WEBCACHE_KEY_OWNER_HOUSE));
		return "ownerHouseList";
	}

	/**
	 * 功能描述：得到系统中银行信息列表
	 *
	 * @author 付湘辉
	 * Created on 2008-05-23
	 *
	 * @return String
	 */
	@SuppressWarnings("unchecked")
	public String getBankList(){
		List<BankVO> list = super.feeBankService.getAllBankList();
		this.setAttribute("banklist", list);
		return "ok";
	}

	/**
	 * Function: 新增业主界面的个人详细信息
	 *
	 * Create author:付湘辉
	 * Create on:2008-6-11
	 * Edit author:
	 * Edit on:
	 * Why:
	 * @param index
	 * @return
	 */
	public String getIndividualDetailCacheByIndex(@Read(key = "index")Integer index) {
		IndividualVO individualVO = (IndividualVO) super.getOneCustomerBaseByIndexFromCache(
				CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL, index);
		individualVO.setCertificateTypeName(super.getCertifiCateTypeName(individualVO.getCertificateType()));
		individualVO.setBirthDateDisplayValue(DateUtil.convertDateToStr(individualVO.getBirthDate(), DateUtil.DEFAULT_SHORT_DATE_FORMAT));
		if (individualVO != null) {
			// 已选择的兴趣爱好集合
//			if (!BlankUtil.isBlank(individual.getInterest())) {
//				List<InterestVO> list = new ArrayList<InterestVO>();
//				this.filtrateExistentInterest(individual.getInterest(),
//						super.getAllInterestList(), list);
//				StringBuffer sb = new StringBuffer();
//				for (InterestVO interest : list) {
//					sb.append(interest.getName()).append(",");
//				}
//				individual.setInterestNameStr(sb.toString().substring(0,
//						sb.toString().length() - 1));
//			}
			this.setAttribute("individual", individualVO);
		}
		return "initOwnerIndividual";
	}

	/**
	 * 功能描述：通过房屋Id在指定key的缓存集合中查找一个住房信息VO对象，
	 *
	 * @author 付湘辉
	 * Created on 2008-05-28
	 * @param key
	 *            在缓存中的key
	 * @param houseId
	 *            住房信息id
	 * @return boolean
	 */
	@Override
	@SuppressWarnings("unchecked")
	public CustomerHouseVO getOneCustomerHouseByHouseIdFromCache(String key, Long houseId) {

		if (BlankUtil.isBlank(houseId)) {
			return null;
		}

		if (BlankUtil.isBlank(key)) {
			key = OwnerAction.WEBCACHE_KEY_OWNER_HOUSE;
		}

		return super.getOneCustomerHouseByHouseIdFromCache(key, houseId);
	}

	/**
	 * Function: 新增业主界面的企业详细信息
	 *
	 * Create author:付湘辉
	 * Create on:2008-6-11
	 * Edit author:
	 * Edit on:
	 * Why:
	 * @param index
	 * @return
	 */
	public String getOrganizationDetailCacheByIndex(@Read(key = "index")Integer index) {
		OrganizationVO organizationVO = (OrganizationVO) super.getOneCustomerBaseByIndexFromCache(
				CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL, index);
		// 法人证件类型名称
		organizationVO.setCertificateTypeName(super.getCertifiCateTypeName(organizationVO.getCertificateType()));
		// 代理人证件类型名称
		organizationVO.setConsignerCertificateTypeName(super.getCertifiCateTypeName(organizationVO.getConsignerCertificateType()));
		// 法人出生日期显示值
		organizationVO.setCorporationBirthDateDisplayValue(DateUtil.convertDateToStr(organizationVO.getCorporationBirthDate(), DateUtil.DEFAULT_SHORT_DATE_FORMAT));
		if (organizationVO != null) {
			this.setAttribute("organization", organizationVO);
		}

		return "initOwnerOrganization";
	}

	/**
	 * 功能描述:某个房间的业主列表（前台收费部分）
	 * @param
	 * @return
	 *
	 * Create author:xuhaidui
	 * Create on:2008-8-22
	 * Edit author:
	 * Edit on:
	 * Why:
	 */
	public String getOwnerList(@Read(key="keyword")@Out(key="keyword") Long keyword,
			@Read(key="proRightId")@Out(key="proRightId") Long proRightId,
			@Read(key = "ec_crd",defaultValue="10")	int pageSize,
            @Read(key = "ec_p", defaultValue="1")	int pageNo){

		List<CustomerVO> list = ownerService.getAllOwnerByHouseId(keyword,proRightId);
		this.getRequest().setAttribute("ownerList", list);
		this.getRequest().setAttribute("totalRows", new Integer(list.size()));
		return "ownerList";
	}

	public IOwnerService getOwnerService() {
		return ownerService;
	}

	public String initIndividual(){
		this.setAttribute("editFlag", "editFlag");
		return "ownerIndividualEdit";
	}


	/**
	 * 功能描述：添加业主的添加主页面
	 * <b>注意：<b>在进入此功能时，应先清空会话中缓存信息，以保证数据准确性。
	 * @author yixianjian
	 * Create on:2008-5-27
	 * @param
	 * @return 返回页面
	 */
	public String initOwnerAddMain() {
		// 先清空缓存
		this.clearCache();

//------------判断是不是由产权变更模块调用----------------------------------
		String type = this.getRequest().getParameter("type");
		String houseId = this.getRequest().getParameter("houseId");
		if (!BlankUtil.isBlank(type) && !BlankUtil.isBlank(houseId)){
			if ("goOut".equals(type)) {
				this.getRequest().setAttribute("type", type);
				this.getRequest().setAttribute("houseId", houseId);
				HouseVO houseVO = houseService.getFlatHouseById(Long
						.valueOf(houseId));
				CustomerHouseVO customerHouseVO = new CustomerHouseVO();
				customerHouseVO.setHouseId(houseVO.getKeyword());
				customerHouseVO.setHouseNumber(houseVO.getHouseNumber());
				addCustomerHouseCache(1, 5, customerHouseVO);
			}
		}
//-------------------------------------------------
		return "initOwnerAddMain";
	}

	/**
	 * 功能描述：初始化业主基本资料添加页面
	 *
	 * @author 付湘辉
	 *
	 * Created on  2008-05-22
	 * @return String
	 * @roseuid 482AA275000F
	 */
	public String initOwnerBaseAdd(@Read(key="addFlag") String addFlag,
								   @Read(key="certificateType") String certificateType,
								   @Read(key="certificateNo") String certificateNo) {

		List certificateTypeList = this.getCertificateType();
		List interestList = this.getAllInterestList();
		if (addFlag != null && addFlag.equals("1")) {
			//查询已有个人资料
			IndividualVO individualVO =
				super.customerService.queryParticipant(certificateType, certificateNo);
			individualVO.setHasSave(ICacheManage.SAVED);

			this.setAttribute("individualOwnerBase", individualVO);
		}
		this.setAttribute("certificateTypeList", certificateTypeList);
		this.setAttribute("interestList", interestList);
		this.setAttribute("sysDate",this.customerService.getDate());
		return "ownerBaseAdd";
	}

	/**
	 * 功能描述：初始化并跳转到 业主详细资料基本资料页面
	 *
	 * @author 付湘辉
	 * Created on 2008-05-23
	 *
	 * @param participantId 参与人ID
	 * @param customerTypeCode - 001 //个人 002 //企业
	 * @return String ownerBaseDetailMain.jsp
	 * @roseuid 48314A360186
	 */
	public String initOwnerBaseDetailMain(@Read(key = "baseIndex")
	Integer index, @Read(key = "curParticipantTypeCode")
	String participantTypeCode) {

		this.setAttribute("baseIndex", index.toString());
		this.setAttribute("curParticipantTypeCode", participantTypeCode);

		if (CustomerVO.INDIVIDUAL_CODE.equals(participantTypeCode)) {
			IndividualVO individualVO =  (IndividualVO)super.getOneCustomerBaseByIndexFromCache(CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL, index);
			this.setAttribute("individual", individualVO);
		}else{

			OrganizationVO organizationVO = (OrganizationVO)super.getOneCustomerBaseByIndexFromCache(CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL, index);
			this.setAttribute("organization", organizationVO);
		}

		return "initOwnerBaseDetailMain";
	}

	/**
	 * 功能描述：初始化业主基本资料修改页面
	 *
	 * @author 付湘辉
	 * Created on 2008-05-23
	 *
	 * @param participantId 参与人id
	 * @return String
	 * @roseuid 482AA33A0128
	 */
	public String initOwnerBaseEdit(@Read(key = "ownerBaseIndex")Integer index,
			@Read(key="customerTypeCode") String customerTypeCode) {
		List certificateTypeList = this.getCertificateType();
		List<InterestVO> interestList = this.getAllInterestList();
		List<InterestVO> removeList = new ArrayList<InterestVO>();
		this.setAttribute("certificateTypeList", certificateTypeList);
		this.setAttribute("sysDate",this.customerService.getDate());

		if (CustomerVO.INDIVIDUAL_CODE.equals(customerTypeCode)) {
			IndividualVO individualVO
	        = (IndividualVO)this.getOneCustomerBaseByIndexFromCache(CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL,
	        		index);
			this.setAttribute("individualOwnerBase", individualVO);

			String interestString = individualVO.getInterest();

			super.filtrateExistentInterest(interestString, interestList,removeList);
			this.setAttribute("selectInterestList", removeList);
			this.setAttribute("interestList", interestList);
			return "ownerIndividualEdit";
		}else{
			OrganizationVO organizationVO
	        = (OrganizationVO)this.getOneCustomerBaseByIndexFromCache(CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL,
	        														  index);
			this.setAttribute("organization", organizationVO);
			return "ownerEnterpriseEdit";
		}

	}

	/**
	 * 功能描述：
	 *
	 * @author 付湘辉
	 * Created on 2008-05-23
	 *
	 * @return String
	 * @roseuid 4831132202DE
	 */
	public String initOwnerBaseEditMain(@Read(key="participantId") Long participantId,
            							@Read(key="participantTypeCode") String participantTypeCode) {

		//001为个人  002为企业
		if(CustomerVO.INDIVIDUAL_CODE.equals(participantTypeCode)) {
//			IndividualVO individualVO = (IndividualVO)getRequest().getSession().getAttribute("individual");
			IndividualVO individualVO = (IndividualVO) this
					.getOneCustomerBaseByIdFromCache(
							CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL, participantId);
			this.getRequest().setAttribute("individualOwnerBase", individualVO);
//			getRequest().getSession().removeAttribute("individual");

			//处理兴趣爱好
			List<InterestVO> interestList = this.getAllInterestList();
			List<InterestVO> removeList = new ArrayList<InterestVO>();
			String interestString = individualVO.getInterest();
			this.filtrateExistentInterest(interestString, interestList,removeList);
			this.getRequest().setAttribute("interestList", interestList);
			this.setAttribute("selectedInterest", removeList);
			this.getRequest().setAttribute("type", "001");
		}
		if(CustomerVO.ORGNIZATION_CODE.equals(participantTypeCode)) {
			OrganizationVO organization = (OrganizationVO)this
			.getOneCustomerBaseByIdFromCache(
					CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL,participantId);
			this.getRequest().setAttribute("organization",organization);
//			getRequest().getSession().removeAttribute("organization");
			this.getRequest().setAttribute("type", "002");
		}
		//初始化下拉列表
		this.getRequest().setAttribute("certificateTypeList", this.getCertificateType()); //证件类型

		return "ownerBaseEditMain";
	}

	/**
	 * 功能描述：初始化业主基本资料列表页面
	 *
	 * @author 付湘辉
	 * Created on 2008-05-23
	 * @return String
	 * @roseuid 482AA3E300EA
	 */
	public String initOwnerBaseList(@Read(key = "ec_p",defaultValue="1") Integer currentPage,
			  						@Read(key = "ec_crd",defaultValue="3")Integer pageSize) {

		List<CustomerVO> list = super.findCustomerBaseListCachePage(currentPage, pageSize);
		this.setAttribute("ownerBaseList", list);
		this.setAttribute("totalRows", Integer.valueOf(list.size()));
		return "ownerBaseList";
	}



	/**
	 * 功能描述:添加业主资料页面的基本资料页面
	 *
	 * @author yixianjian

	 * Create on:2008-5-27
	 * @return String
	 */
	public String initOwnerBaseMain() {
		 String houseId=	this.getRequest().getParameter("houseId");
		 String type = this.getRequest().getParameter("type");
		 if (!BlankUtil.isBlank(houseId) && !BlankUtil.isBlank(type)){
			 this.getRequest().setAttribute("houseId", houseId);
			 this.getRequest().setAttribute("type", type);
		 }

		return "initOwnerBaseMain";
	}

	/**
	 * 功能描述：在当前住户管理页面双击鼠标，初始化并跳转到页面： pms/customer/owner/ownerDetailMain.jsp
	 * <b>注意：<b>在进入详细资料功能时，应先清空会话中缓存信息，以保证数据准确性。
	 *
	 * @author 付湘辉
	 * Created on 2008-05-23
	 *
	 * @param participantId 参与人id
	 * @param participantTypeCode - 参与人类型编码
	 *   如： 001 -（个人） 002 -（企业）
	 *
	 * @return String
	 * @roseuid 4831472900AB
	 */
	public String initOwnerDetailMain(@Read(key = "curParticipantId")
	Long participantId, @Read(key = "curParticipantTypeCode")
	String participantTypeCode)  {

		//清空缓存
		this.clearCache();

		List<CustomerHouseVO> list = this.ownerService.getOwnerHouseListById(participantId);

		//添加到缓存中
		if (!BlankUtil.isBlank(list)) {
			for (CustomerHouseVO houseVO : list) {
				super.addOneCustomerHouseToCache(OwnerAction.WEBCACHE_KEY_OWNER_HOUSE, houseVO, false);
			}
		}

		CustomerVO customer = null;

		if (CustomerVO.ORGNIZATION_CODE.equals(participantTypeCode)) {
			customer = this.ownerService.findOrganizationById(participantId);
			if (BlankUtil.isBlank(customer)) {
				customer = new OrganizationVO();
			}
		}else{
			customer =  this.ownerService.findIndividualById(participantId);
			if (BlankUtil.isBlank(customer)) {
				customer = new IndividualVO();
			}
		}

		super.addOneCustomerBaseToCache(CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL, customer, false);

		super.setAllStatusToDone(OwnerAction.WEBCACHE_KEY_OWNER_HOUSE);
		super.setAllStatusToDone(CustomerAction.WEBCACHE_KEY_CUSTOMER_ALL);

		this.setAttribute("baseIndex", customer.getIndex().toString());
		this.setAttribute("curParticipantId", participantId.toString());
		this.setAttribute("curParticipantTypeCode", participantTypeCode);

		return "initOwnerDetailMain";
	}

	/**
	* Function:跳转到业主房屋修改页面
	* <b>注意：<b>在进入此功能时，应先清空会话中缓存信息，以保证数据准确性。
	*
	* Create author:fuxianghui
	* Create on:2008-5-28
	* Edit author:yixianjian
	* Edit on:2008-5-28
	* Why:修改返回值，跳转到编辑页面
	*
	* @param participantId
	* @param customerTypeCode
	* @return
	 */
	public String initOwnerEditMain(@Read(key = "houseId") Long participantId,
									@Read(key = "houseId") String customerTypeCode) {
		this.clearCache();
		return "ownerEditMain";
	}

	/**
	 * 功能描述：
	 *
	 * @author 付湘辉
	 * Created on 2008-05-27
	 *
	 * @return String
	 * @roseuid 48290ADE0280
	 */
	public String initOwnerHouseAdd() {
		this.getBankList();
		return "ownerHouserAdd";
	}
	/**
	 * 功能描述：在新增业主页面修改业主住房信息
	 *
	 * @author 付湘辉
	 *
	 * Created on  2008-05-22
	 * @param houseId
	 * @return java.lang.String
	 * @roseuid 482936C503D8
	 */
	public String initOwnerHouseEdit(@Read(key = "edit_houseId") Long houseId) {
		this.getBankList();
		CustomerHouseVO chvo = this.getOneCustomerHouseByHouseIdFromCache(OwnerAction.WEBCACHE_KEY_OWNER_HOUSE, houseId);
		if (BlankUtil.isBlank(chvo)) {
			return "";
		}
		this.setAttribute("ownerHouse", chvo);
		return "ownerHouseEdit";
	}






	/**
	 * 功能描述：初始化新增时住房信息列表
	 *
	 * @author yixianjian
	 * Create on:2008-5-27
	 * @param
	 * @return 返回页面
	 */
	public String initOwnerHouseList(@Read (key="contextMenuFlag") String flag,
									 @Read(key = "ec_p",defaultValue="1") Integer currentPage,
									 @Read(key = "ec_crd",defaultValue="5")Integer pageSize) {

		//---------判断是不是由产权变更模块调用---------------------------------------------------------------
			String houseId = this.getRequest().getParameter("houseId");
			String type=this.getRequest().getParameter("type");

			if (!BlankUtil.isBlank(houseId) && !BlankUtil.isBlank(type)){
				if ("goOut".equals(type)) {
				HouseVO houseVO = houseService.getFlatHouseById(Long
						.getLong(houseId));
				this.getRequest().setAttribute("houseVO", houseVO);
				this.getRequest().setAttribute("houseId", houseId);
				this.getRequest().setAttribute("type", type);
			}
			}

		//-----------------------------------------------------------------------

		//	标志flag用于在返回页面是否弹出右键菜单
		if (!BlankUtil.isBlank(flag)) {
			this.setAttribute("contextMenuFlag", flag);
		}

		List<CustomerHouseVO> list = this.findOwnerHouseListCacheInner(currentPage, pageSize);
		this.setAttribute("ownerHouseList", list);
		this.setAttribute("totalRows", Integer.valueOf(list.size()));


		return "ownerHouseList";
	}


	/**
	 *
	 * 功能描述: 初始化修改时住房信息列表
	 *
	 * @author 付湘辉
	 * Created on:2008-6-13
	 *
	 * 修改原因：
	 * @param participantId 参与人id
	 * @return String 返回结果
	 */
	public String initOwnerHouseListOnEdit(@Read (key="participantId")Long participantId){
		//先清空房屋信息Session缓存
		this.getRequest().getSession().removeAttribute(OwnerAction.WEBCACHE_KEY_OWNER_HOUSE);

		List<CustomerHouseVO> list = this.ownerService.getOwnerHouseListById(participantId);
		Long creator = super.getUserId();
		for (CustomerHouseVO houseVO : list) {
			houseVO.setCreator(creator);
			super.addOneCustomerHouseToCache(OwnerAction.WEBCACHE_KEY_OWNER_HOUSE, houseVO, false);
		}

		super.setAllStatusToDone(OwnerAction.WEBCACHE_KEY_OWNER_HOUSE);
		this.setAttribute("totalRows", Integer.valueOf(list.size()));
		this.setAttribute("ownerHouseList", list);
		return "ownerHouseList";
	}

	/**
	* Function:
	* @param
	* @return
	* Create author:yixianjian
	* Create on:2008-6-27
	* Edit author:
	* Edit on:
	* Why:
	 */
	public void loadHouseContractNumberAndPropertyNo(@Read(key="houseNumber") String houseNumber){
		CustomerHouseVO chvo = super.customerService.findCustomerHouseByHouseNumber(houseNumber);

//		HouseDomain house = super.houseService.getHouseByNumber(houseNumber, false);
		// 取得给定id的房间的当前可用银行帐号
//		BankAccountVO bankAccountVo = super.bankAccountService.getCurrentBankAccount(house.getKeyword());

		StringBuffer jsString = new StringBuffer();
		if (!BlankUtil.isBlank(chvo)) {
			jsString.append("{\"houseContractNumber\":");
			String houseContractNumber =getStringNotNull(chvo.getHouseContractNumber());
			jsString.append("\"").append(houseContractNumber).append("\"");

			jsString.append(",\"housePropertyNo\":");
			String housePropertyNo = getStringNotNull(chvo.getHousePropertyNo());
			jsString.append("\"").append(housePropertyNo ).append("\"");

			jsString.append(",\"manageHouseId\":");
			String manageHouseId = String.valueOf(chvo.getManageHouseId());
			jsString.append("\"").append(manageHouseId ).append("\"");

			//银行ID
			String bankId = chvo == null ? "" : String.valueOf(chvo.getBankId());
			jsString.append(",\"bankId\":").append("\"").append(bankId).append("\"");
			//银行名称
			String bankName = getStringNotNull(chvo == null ? null : chvo.getBankName());
			jsString.append(",\"bankName\":").append("\"").append(bankName).append("\"");
			//银行帐号
			String accNumber = getStringNotNull( chvo == null ? null :  chvo.getBankNumber());
			jsString.append(",\"bankNumber\":").append("\"").append(accNumber).append("\"");
			//开户人
			String accOwner =getStringNotNull( chvo == null ? null :  chvo.getAccountOwner());
			jsString.append(",\"accountOwner\":").append("\"").append(accOwner).append("\"");
			// 银行合同号
			String contactNumber = getStringNotNull(chvo == null ? null : chvo.getContactNumber());
			jsString.append(",\"contactNumber\":").append("\"").append(contactNumber).append("\"");

			Boolean flag = true;
			if(!BlankUtil.isBlank(accNumber)) {
				flag = collectionService.isIn(accNumber);
			}

			jsString.append(",\"isIn\":").append("\"").append(flag.toString()).append("\"");

			jsString.append("}");
		}
		super.renderText(jsString.toString());
	}

	/**
	* Function:根据证件类型和证件号码，查询业主.
	* @param
	* @return
	* Create author:yixianjian
	* Create on:2008-6-13
	* Edit author:
	* Edit on:
	* Why:
	 */
	public String loadIndividual(@Read(key = "certificateType") String certificateType,
								@Read(key = "certificateNo") String certificateNo){
		//查询已有个人资料
		IndividualVO individualVO = super.customerService.queryParticipant(certificateType, certificateNo);
		individualVO.setHasSave(ICacheManage.SAVED);
		this.setAttribute("individualOwnerBase", individualVO);

		List certificateTypeList = this.getCertificateType();
		List<InterestVO> interestList = this.getAllInterestList();
		List<InterestVO> removeList = new ArrayList<InterestVO>();
		String interestString = individualVO.getInterest();
		this.filtrateExistentInterest(interestString, interestList,removeList);
		this.setAttribute("certificateTypeList", certificateTypeList);
		this.setAttribute("interestList", interestList);
		this.setAttribute("selectInterestList", removeList);
		return "ownerIndividualEdit";
	}

	public void setOwnerService(IOwnerService ownerService) {
		this.ownerService = ownerService;
	}

	/**
	 * 功能描述: <p>在新建或修改企业业主时，输入企业名称后，需要验证在绶存中是否已经存在相同的名称，
	 * 如果系统中已存在这个企业，验证其与缓存中房屋的关系。</p>
	 * <p>这里的缓存是指页面数据缓存，在新增，修改业主时用到，参见 {@link com.ce.pms.common.web.ICacheManage}。</p>
	 * <b>验证规则：</b>
	 * <ol>
	 * <li>如果绶存中已存在该名称的企业，验证不通过。</li>
	 * <li>查询系统中如果已存在这个企业，与缓存中已选择的房屋逐个比较，如果这个企业已经是其中一间房的业主或租户，验证不通过。</li>
	 * </ol>
	 * @param participantName
	 *
	 * @author
	 * Create author:付湘辉 <br>
	 * Create on:2008-7-30  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public String validateOrganizationOwner(@Read OrganizationVO organizationVO,
			                                @Read (key="optionType")String optionType){
		return super.validateOrganizationLoadForRenderText(organizationVO, WEBCACHE_KEY_OWNER_HOUSE, optionType);
	}

	/**
	 * Function:输入证件类型和证件号码后，需要确认该证件类型和号码是否能输入
	 * (如果对应的参与人已经是业主、租户、家庭成员则不能登记)。 <br>
	 * 如果可以输入,则提示用户是否导入。
	 * 如果不可以输入，则提示用户，说明该参与人已经是业主、
	 * 租户、或者是家庭成员，要求重新填写。 <br>
	 * @param certificateNo 证件号码
	 * @param certificateType 证件类型
	 * @param oldPid旧的参与人ID
	 * @param newPid新的参与人ID
	 * @param optionType 操作类型  isAddADD是新增中的新增 isAddEdit是新增中的修改 isEdit是修改
	 * @return
	 * Create author:yixianjian
	 * Create on:2008-7-4
	 * Edit author:
	 * Edit on:
	 * Why:
	 */
	public String validateOwnerAllowLoad(@Read IndividualVO individualVO,
										@Read(key="optionType")String optionType){
		return super.validateIndividualLoadForRenderText(individualVO,
														 WEBCACHE_KEY_OWNER_HOUSE,
														 optionType);
	}

    /**
	 * 功能描述:选择房间时,验证银行帐号是否可以修改<br>
	 * 当银行帐号处于出盘状态且没有回盘时,则不能修改帐号。
	 * 否则可以修改帐号.
	 * Create author:yixianjian <br>
	 * Create on:2008-10-27  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public void validationBankAllowEdit(@Read(key="bank")String bankNumber){
		if(BlankUtil.isBlank(bankNumber)) return;
		Boolean flag = collectionService.isIn(bankNumber);
		renderText(flag.toString());
	}

	/**
	 * 功能描述：验证指定房号
	 *
	 * @author 付湘辉
	 * Created on 2008-05-27
	 *
	 * @param houseNumber
	 * @return String
	 */
	public String validationHouse(@Read(key="houseNumber") String houseNumber) {
		String cacheKey = OwnerAction.WEBCACHE_KEY_OWNER_HOUSE;
		return super.validationHouseForRenderText(houseNumber, cacheKey);
	}

	/**
	 *
	 * 功能描述: 查询除指定房号外的其它房屋中,所关联的指定合同号或者产权号是否存在
	 * 注意:参数contactNO 和 proRightNO 有一个应该为空
	 * @author 付湘辉
	 * Created on:2008-6-26
	 *
	 * 修改原因：
	 * @param housePropertyNo
	 * @param houseContractNumber
	 * @return
	 * @return String 返回结果
	 */
	public String validationHousePropertyContractNumber(
						@Read(key="houseNumber") String houseNumber,
						@Read(key = "housePropertyNo") String housePropertyNo,
						@Read(key = "houseContractNumber") String houseContractNumber) {
		String res = this.queryProrightContract(houseNumber, housePropertyNo, houseContractNumber);
		this.renderText(res);
		return null;
	}

	/**
	 *
	 * 功能描述:得到缓存中住房信息，
	 * 如果没有数据，此方法返回一个实例化的空列表容器
	 * 操作标志opratorFlag：如果此参数为真值，则会返回一个过滤了删除状态记录的列表，
	 * 否则完整返回
	 *
	 * @author 付湘辉
	 * Created on:2008-5-30
	 *
	 * 修改原因：
	 * @param opratorFlag 操作标志
	 * @return LinkedList<CustomerHouseVO> 返回结果
	 */
	@SuppressWarnings("unchecked")
	protected LinkedList<CustomerHouseVO> getOwnerHouseListCacheHerebyFlag(boolean opratorFlag) {
		return super.getCustomerHouseListCacheHerebyFlag(OwnerAction.WEBCACHE_KEY_OWNER_HOUSE, opratorFlag);
	}

	/** 功能描述:  <br>
	 * @param sourceCH
	 * @param targetCH
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-11-8  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	*/
	protected void updateCustomerHouseBankAccValues(final CustomerHouseVO sourceCH, CustomerHouseVO targetCH) {
		super.updateCustomerHouseBankAccValues(sourceCH, targetCH);
	}

	/** 功能描述: 在修改业主时对业主基本资料信息数据准确性进行验证 <br>
	 * @param operateType TODO
	 * @param individualVO
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-10-31  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	*/
	protected Boolean validateOwnerOnEditSave(CustomerVO customerVO,String houseKey, String operateType) {
		return super.validateCustomerOnEditSave(customerVO, OwnerAction.WEBCACHE_KEY_OWNER_HOUSE, operateType);
	}

	/** 功能描述: 在新增业主时对业主基本资料信息数据准确性进行验证 <br>
	 * @param customerVO
	 * @param houseKey
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-10-31  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	*/
	protected Boolean validateOwnerOnSave(CustomerVO customerVO,String houseKey) {
		return super.validateCustomerOnSave(customerVO, OwnerAction.WEBCACHE_KEY_OWNER_HOUSE);
	}

	/** 功能描述:  <br>
	 * @param customerHouseVO
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-9-1  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	*/
	private boolean canAddBankAccount(CustomerHouseVO customerHouseVO) {
		return this.ownerService.canAddBankAccount(customerHouseVO);
	}

	/**
	 * 功能描述：从房屋信息缓存中查询业主住房信息分页列表
	 *
	 * @author 付湘辉
	 * Created on 2008-05-28
	 *
	 * @param currentPage 当前页码
	 * @param pageSize 页大小
	 * @return List 一个房屋信息的分页列表
	 */
	@SuppressWarnings("unchecked")
	private List<CustomerHouseVO> findOwnerHouseListCacheInner(Integer currentPage,Integer pageSize){
		LinkedList<CustomerHouseVO> list = this.getOwnerHouseListCacheHerebyFlag(true);

		if (list==null) {
			return new ArrayList<CustomerHouseVO>();
		}

		//Collections.sort(list);

		List<CustomerHouseVO> resultList = super.paginationList(currentPage, pageSize, list);

		return resultList;
	}

	private String getStringNotNull(String str){
		if(str == null) return "";
		return str;
	}

	/**
	 *
	 * 功能描述: 查询除指定房号外的其它房屋中,所关联的指定合同号或者产权号是否存在
	 * 注意:参数contactNO 和 proRightNO 有一个应该为空
	 * @author 付湘辉
	 * Created on:2008-6-26
	 *
	 * 修改原因：
	 * @param housePropertyNo
	 * @param houseContractNumber
	 * @return
	 * @return String 返回结果
	 */
	private String queryProrightContract(String houseNumber,String housePropertyNo,String houseContractNumber) {
		//该验证房号不能为空
		if(BlankUtil.isBlank(houseNumber)){
			return CustomerAction.HOUSENO_ISNULL;
		}

		if (BlankUtil.isBlank(housePropertyNo) && BlankUtil.isBlank(houseContractNumber)) {
			//合同号和产权证号如果都为空
			return OwnerAction.PRORIGHT_AND_CONTRACT_ISNULL;
		}

		List<CustomerHouseVO> list = super.getCustomerHouseListCacheHerebyFlag(OwnerAction.WEBCACHE_KEY_OWNER_HOUSE, true);
		for (CustomerHouseVO houseVO : list) {
			if (!houseNumber.equalsIgnoreCase(houseVO.getHouseNumber())) {
				if (!BlankUtil.isBlank(housePropertyNo)) {
					if (housePropertyNo.equalsIgnoreCase(houseVO.getHousePropertyNo())) {
						return super.getLocaleMessage("customer:proright_cache_exist_exception");
					}
				}else{
					if (houseContractNumber.equalsIgnoreCase(houseVO.getHouseContractNumber())) {
						return super.getLocaleMessage("customer:contact_cache_number_exist_exception");
					}
				}
			}
		}

		//开始验证
		Integer count = this.ownerService.getProRightCountByHouse(houseNumber, houseContractNumber, housePropertyNo);
		if(SysrefcodeDO.CONSTANTS_ZERO < count) {
			return super.getLocaleMessage("customer:proright_exist_exception");
		}
		return CustomerAction.NORMAL_STATE;
	}

}
